package com.mg.common.exception;

import com.mg.common.vo.ResponseResult;
import com.mg.common.vo.ResponseStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author tomyeung-李尐达
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ServiceException.class)
    public ResponseResult serviceExceptionHandler(ServiceException e){
        return ResponseResult.ok(e.getMessage());
    }

    @ExceptionHandler(BaseException.class)
    public ResponseResult baseExceptionHandler(BaseException e){
        return ResponseResult.error(ResponseStatus.FAIL);
    }
    @ExceptionHandler(Exception.class)
    public ResponseResult otherExceptionHandler(Exception e)
    {
        return ResponseResult.error(ResponseStatus.OTHER_UNKNOWN_ERROR);
    }
}
